module AutoBase
  class ActionWord
    class Call
      def initialize(session)
        @session = session
      end

      def method_missing(meth, *args)
        path, file = meth.to_s.split('__')
        if file
          path = path.split('_')
          full = File.join path, file
        else
          full = path
        end

        name = meth.to_s.downcase
        AutoBase::ActionWord::Index.name = name
        require full + '.aw'

        file = AutoBase::ActionWord::Index[name]

        if args.size == 1
          param = args.first
        else
          param = args
        end

        action_word = AutoBase::DefActionWord.new
        action_word.param = param
        action_word.instance_eval(IO.read(file), file, 0)

        AutoBase::ActionWord::Instance.new(action_word)
      end
    end
  end
end